Skip to content

Conversation

@zhaohb
Copy link
Contributor

@zhaohb zhaohb commented Nov 19, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 19, 2025 05:35

This comment was marked as duplicate.

@Wovchena Wovchena requested a review from yatarkan November 19, 2025 07:57
Copilot AI review requested due to automatic review settings November 19, 2025 10:16

This comment was marked as duplicate.

Copilot AI review requested due to automatic review settings December 3, 2025 08:40

This comment was marked as duplicate.

@zhaohb zhaohb requested a review from yatarkan December 3, 2025 08:50
Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings December 3, 2025 09:02
zhaohb and others added 2 commits December 3, 2025 17:03
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>

This comment was marked as duplicate.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 10 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings December 5, 2025 01:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +132 to +133
snprintf(message_json, sizeof(message_json),
"{\"role\": \"user\", \"content\": \"%s\"}", escaped_prompt);
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snprintf call doesn't check for truncation. If the formatted string exceeds MAX_JSON_LENGTH, snprintf will truncate it and return a value >= MAX_JSON_LENGTH. This could result in malformed JSON being passed to ov_genai_json_container_create_from_json_string, leading to JSON parsing errors. Consider checking the return value of snprintf to ensure the formatted string fits within the buffer.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings December 5, 2025 04:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +75
static void json_escape_string(const char* input, char* output, size_t output_size) {
size_t i = 0;
size_t j = 0;
while (input[i] != '\0' && j < output_size - 1) {
switch (input[i]) {
case '"':
if (j < output_size - 2) {
output[j++] = '\\';
output[j++] = '"';
}
break;
case '\\':
if (j < output_size - 2) {
output[j++] = '\\';
output[j++] = '\\';
}
break;
case '\n':
if (j < output_size - 2) {
output[j++] = '\\';
output[j++] = 'n';
}
break;
case '\r':
if (j < output_size - 2) {
output[j++] = '\\';
output[j++] = 'r';
}
break;
case '\t':
if (j < output_size - 2) {
output[j++] = '\\';
output[j++] = 't';
}
break;
default:
output[j++] = input[i];
break;
}
i++;
}
output[j] = '\0';
}
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON escape function has incomplete escape handling. It's missing essential JSON escape sequences like '\b' (backspace) and '\f' (form feed). Additionally, control characters (0x00-0x1F) should be escaped as "\uXXXX" according to JSON specification. Consider using a more complete JSON escaping implementation or a JSON library.

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +133
snprintf(message_json, sizeof(message_json),
"{\"role\": \"user\", \"content\": \"%s\"}", escaped_prompt);
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential buffer overflow: snprintf is called with sizeof(message_json) (4096 bytes) but writes escaped_prompt which can be up to (MAX_PROMPT_LENGTH - 1) * 2 + 1 = 2047 bytes, plus the JSON template string {"role": "user", "content": ""} (32 bytes). If the user enters close to MAX_PROMPT_LENGTH characters with many escapable characters, the result could exceed the 4096 byte buffer. The buffer size calculation should account for the worst-case scenario of the escaped string plus JSON formatting overhead.

Copilot uses AI. Check for mistakes.
NULL)); // Only the streamer functionality is used here.

// Skip empty lines
if (strlen(prompt) == 0) {
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop continues when an empty line is encountered, but this will cause "question:" to not be printed after skipping. This means multiple empty lines will result in no prompt being shown. Consider printing the prompt after the continue statement, or restructure the logic to handle empty lines more gracefully.

Suggested change
if (strlen(prompt) == 0) {
if (strlen(prompt) == 0) {
printf("question:\n");

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +47
* @param history A pointer to the newly created ov_genai_chat_history.
* @param messages A JsonContainer containing an array of message objects.
* @return ov_genai_chat_history_status_e A status code, return OK(0) if successful.
*/
OPENVINO_GENAI_C_EXPORTS ov_genai_chat_history_status_e ov_genai_chat_history_create_from_json_container(
ov_genai_chat_history** history,
const ov_genai_json_container* messages
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent parameter ordering with similar functions. This function has parameters ordered as (output, input), while ov_genai_json_container_create_from_json_string uses (input, output) ordering. For consistency across the API, consider reordering to match the pattern where input parameters come before output parameters.

Suggested change
* @param history A pointer to the newly created ov_genai_chat_history.
* @param messages A JsonContainer containing an array of message objects.
* @return ov_genai_chat_history_status_e A status code, return OK(0) if successful.
*/
OPENVINO_GENAI_C_EXPORTS ov_genai_chat_history_status_e ov_genai_chat_history_create_from_json_container(
ov_genai_chat_history** history,
const ov_genai_json_container* messages
* @param messages A JsonContainer containing an array of message objects.
* @param history A pointer to the newly created ov_genai_chat_history.
* @return ov_genai_chat_history_status_e A status code, return OK(0) if successful.
*/
OPENVINO_GENAI_C_EXPORTS ov_genai_chat_history_status_e ov_genai_chat_history_create_from_json_container(
const ov_genai_json_container* messages,
ov_genai_chat_history** history

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@yatarkan yatarkan Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot's proposal - align order of input/output params

Copy link
Contributor

@yatarkan yatarkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check and apply Copilot's comments or explain if some of them not applicable

Comment on lines +41 to +47
* @param history A pointer to the newly created ov_genai_chat_history.
* @param messages A JsonContainer containing an array of message objects.
* @return ov_genai_chat_history_status_e A status code, return OK(0) if successful.
*/
OPENVINO_GENAI_C_EXPORTS ov_genai_chat_history_status_e ov_genai_chat_history_create_from_json_container(
ov_genai_chat_history** history,
const ov_genai_json_container* messages
Copy link
Contributor

@yatarkan yatarkan Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot's proposal - align order of input/output params

return OV_GENAI_CHAT_HISTORY_INVALID_PARAM;
}
try {
history->object->push_back(*(message->object));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check that message is json container object

if (index >= history->object->size()) {
return OV_GENAI_CHAT_HISTORY_OUT_OF_BOUNDS;
}
ov::genai::JsonContainer message_ref = (*history->object)[index];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is message_ref actually a reference? If not let's rename accordingly. The same for methods below.

Comment on lines +88 to +89
const ov_genai_json_container* container,
ov_genai_json_container** copy_container);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name it a bit more explicitly for clarification

Suggested change
const ov_genai_json_container* container,
ov_genai_json_container** copy_container);
const ov_genai_json_container* source,
ov_genai_json_container** target);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants